package com.flute.framework.search.result.xmlresult;

public class XmlParserUtil {
	private XmlParserUtil() {
	}

	public static String filter(String str) {
		StringBuilder result = new StringBuilder();
		if (str != null) {
			for (int i = 0; i < str.length(); i++) {
				char c = str.charAt(i);
				int pos = -1;
				for (int j = 0; j < Constants.sources.length; j++) {
					if (c == Constants.sources[j]) {
						pos = j;
						break;
					}
				}
				if (pos >= 0) {
					result.append(Constants.filtered[pos]);
				} else if ((int) c <= 128) {
					result.append(c);
				} else {
					result.append("&#");
					result.append((int) c);
					result.append(";");
				}
			}
		}
		return result.toString();
	}
	
	public static boolean isValid(String nodeName) {
		boolean isValid = false;
		if (nodeName != null) {
			isValid = true;
		}
		return isValid;
	}

	public static void main(String[] args) {
		System.out.println(XmlParserUtil.filter(";\'\"&<>"));
		System.out.println(XmlParserUtil.filter("我爱中国"));
	}
}
